﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace twilters
{
    /**
     * All datastore methods that are used by rest of the app
     */
    public interface DataStore
    {
        /**
         * Opens datastore configuration using configuration
         */
        void Open(ConfigurationHandler configuration);

        /**
         * Closes datastore or database connection
         * Note that this method must be invoked always after using datastore!
         */
        void Close();

        /**
         * Returns a List of filters from the datastore
         */
        List<Filter> findMyFilters(String ownerUsername);

        /**
         * Stores all tweets in list if neccesary
         */
        void storeTweets(List<Tweet> tweets);

        /**
         * Loads and filters tweets by the filter
         */
        List<Tweet> loadFilteredTweets(Filter filter, String followerUsername);

        /**
         * Purges all filters from local datastore
         */
        void purgeFilters();

        /**
         * Deletes given filter from datastor
         */
        void deleteFilter(Filter filter);

        /**
         * Purges all cached tweets from local datastore
         */
        void purgeTweetCache();

        //TODO: define filter parameters
        void storeFilter(Filter filter);

        /**
         * Stores tweet to local datastore
         */
        void storeTweet(Tweet tweet);

        /**
         * Resets ID sequence back to 1
         * 
         * TODO: remove this method declaration from the interface
         */
        void resetIDSequence();

        /**
         * gets next ID from global ID sequence
         */
        int NextId();

        /**
         * stores private data to datastore
         */
        void storePrivateData(PrivateData privateData);

        /**
         * Loads private data from datastore
         */
        PrivateData loadPrivateData();
    }

    class DataStoreException : Exception
    {
        public DataStoreException(String message)
            : base(message)
        {
        }

        public DataStoreException(String message, Exception cause)
            : base(message, cause)
        {
        }
    }
}
